﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Alos.Common
{
    public class FunHelper
    {
        public static void Try(Action action, Action errhander = null)
        {
            try
            {
                action();
            }
            catch (Exception ex)
            {
                if (errhander is Action) errhander();
                Log.errorlog(ex);
            }
        }

        #region Lambda表达式不动点递归
        public static Func<T, TResult> Fix<T, TResult>(Func<Func<T, TResult>, Func<T, TResult>> f)
        {
            return x => f(Fix(f))(x);
        }
        public static Func<T1, T2, TResult> Fix<T1, T2, TResult>(Func<Func<T1, T2, TResult>, Func<T1, T2, TResult>> f)
        {
            return (x, y) => f(Fix(f))(x, y);
        }
        public static Func<T1, T2, T3, TResult> Fix<T1, T2, T3, TResult>(Func<Func<T1, T2, T3, TResult>, Func<T1, T2, T3, TResult>> f)
        {
            return (x, y, z) => f(Fix(f))(x, y, z);
        }
        #endregion
    }
}
